package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.qianfeng.lingshijia.R;

import java.util.ArrayList;
import java.util.List;

import entity.Details;
import utils.DownloadUtils;

/**
 * Created by yerjon 2016/1/14.
 *  商品详情下更多详情界面适配器
 */
public class MoreDetailAdapter extends BaseAdapter{
    List<Details.DataEntity.DescriptionEntity> data;
    private Context context;

    public MoreDetailAdapter(Context context)
    {
        this.context = context;
        data = new ArrayList<>();
    }

    public void setData(List<Details.DataEntity.DescriptionEntity> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private  String imgUrl;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if(convertView == null){
            convertView =  LayoutInflater.from(context).inflate(R.layout.detail_imagelist_item,null);
            vh = new ViewHolder();
            vh.imageView = (ImageView) convertView.findViewById(R.id.id_iv_more);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        imgUrl = data.get(position).getPicUrl();
        DownloadUtils.LoadPicture(imgUrl, vh.imageView);
        return convertView;
    }
    class ViewHolder
    {
        ImageView imageView;
    }
}
